<?PHP

global $conf;
$music=new music;
//check if valid action
$forward=FALSE;
if($conf->qm[0]=='share')
{

	if($conf->qm[1] == 'twitter' || $conf->qm[1] == 'buy' || $conf->qm[1] == 'facebook')
	{
		//print_r($conf->qm);
		if($conf->qm[2] == 'media')
		{
			$music->where['id']=$conf->qm[3];
			$music->get_music();
			if(!empty($music->data))
			{
				$media=current($music->data);
				$forward=TRUE;
			}
			
		}
	}
}

if($forward)
{
	$track_urlencode=urlencode($media['name']." - ".$media['artist']);
	$album_urlencode=urlencode($media['artist']." - ".$media['album']);
	if(empty($media['album']))
	{
		$media_urlencode=$track_urlencode;
	}
	else
	{
		$media_urlencode=$album_urlencode;
	}
	
	if($conf->qm[1] == 'twitter')
	{
		$forward="http://twitter.com/home?status=now playing @pinoytuner: ".$track_urlencode." ";
		
	}
	if($conf->qm[1] == 'buy')
	{
										$forward="http://www.amazon.com/gp/search?ie=UTF8&keywords=".$media_urlencode."&tag=pinoytuner-20&index=music&linkCode=ur2&camp=1789&creative=390957";
	}
	if($conf->qm[1] == 'facebook')
	{
		
		$fb_link=urlencode($conf->absolute_path."media/".$media['id']);			
		$forward="http://www.facebook.com/sharer.php?u=".$fb_link;
		//$forward=$fb_link;
	}
	header('location: '.$forward);
}
else
{
	$conf->page_render='admin/e/404.php';
	$conf->advertise=false;
}
//check if media
//1 check if song is available

?>
